package com.zh.work.service.platform.virtual.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.work.dao.platform.virtual.VirtualCheckMapper;
import com.zh.work.entity.virtual.VirtualCheckEntity;
import com.zh.work.service.platform.virtual.VirtualCheckService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 对账检查实体设置业务逻辑实现层
 * @Author: Li.HuiNeng
 * @Create in: 2019/09/11
 * @Version: 1.0.1
 */
@Service
public class VirtualCheckServiceImpl extends ServiceImpl<VirtualCheckMapper, VirtualCheckEntity> implements VirtualCheckService {

    @Autowired
    private VirtualCheckMapper virtualCheckMapper;


    @Override
    public IPage<VirtualCheckEntity> selectVirtualCheckPages(Page<VirtualCheckEntity> page, VirtualCheckEntity param) {
        return this.virtualCheckMapper.selectPage(
                page,
                new QueryWrapper<VirtualCheckEntity>().lambda()
                        .between(ObjectUtils.allNotNull(param.getStartDate(), param.getEndDate()),
                                VirtualCheckEntity::getCheckDate, param.getStartDate(), param.getEndDate())
                        .between(ObjectUtils.allNotNull(param.getBeginAmount(), param.getEndAmount()),
                                VirtualCheckEntity::getRechargeError, param.getBeginAmount(), param.getEndAmount())
                        .between(ObjectUtils.allNotNull(param.getBeginPayAmount(), param.getEndPayAmount()),
                                VirtualCheckEntity::getPayAmount, param.getBeginPayAmount(), param.getEndPayAmount())
                        .like(StringUtils.isNotEmpty(param.getMerchNo()), VirtualCheckEntity::getMerchNo, param.getMerchNo())
                        .like(StringUtils.isNotEmpty(param.getCardNo()), VirtualCheckEntity::getCardNo, param.getCardNo())
                        .like(Objects.nonNull(param.getCheckStatus()), VirtualCheckEntity::getCheckStatus, param.getCheckStatus())
                        .like(Objects.nonNull(param.getCheckLevel()), VirtualCheckEntity::getCheckLevel, param.getCheckLevel())
        );
    }

}
